package com.xingshentech.ugv.operate.module.httpdata;

import android.content.Context;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.xingshentech.ugv.operate.R;
import com.xingshentech.ugv.operate.module.bean2.AllVehiclePositionBean;
import com.xingshentech.ugv.operate.module.bean2.AppMenu;
import com.xingshentech.ugv.operate.module.bean2.BaseResponseCenter;
import com.xingshentech.ugv.operate.module.bean2.CarListBean;
import com.xingshentech.ugv.operate.module.bean2.CurrentStationInfo;
import com.xingshentech.ugv.operate.module.bean2.PageResult;
import com.xingshentech.ugv.operate.module.bean2.UserBean;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;

public class MockApi {

    private Context context;

    public MockApi(Context context) {
        this.context = context;
    }

    // 读取本地 JSON 文件
    private String readJsonFromRaw(int resourceId) {
        try {
            InputStream is = context.getResources().openRawResource(resourceId);
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            return new String(buffer, StandardCharsets.UTF_8);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    // 模拟网络请求，获取 UserBean
    public UserBean getMockUser() {
        String json = readJsonFromRaw(R.raw.user_data);
        return new Gson().fromJson(json, UserBean.class);
    }

    // 模拟网络请求，获取 appMenu
    public List<AppMenu> getMockAppMenu() {
        String json = readJsonFromRaw(R.raw.app_menu);
        return new Gson().fromJson(json, new TypeToken<List<AppMenu>>() {}.getType());
    }

    public List<CurrentStationInfo> getMockStationList() {
        String json = readJsonFromRaw(R.raw.station_list);
        return new Gson().fromJson(json, new TypeToken<List<CurrentStationInfo>>() {}.getType());
    }

    public  PageResult<List<CarListBean>> getMockCarList() {
        String json = readJsonFromRaw(R.raw.car_list);
        return new Gson().fromJson(json, new TypeToken<PageResult<List<CarListBean>>>() {}.getType());
    }

    public  BaseResponseCenter<Object> notifyMonitorSiteInfo() {
        String json = readJsonFromRaw(R.raw.car_list);
        return new Gson().fromJson(json, new TypeToken<BaseResponseCenter<Object>>() {}.getType());
    }

    public Boolean controlCharge() {
        String json = readJsonFromRaw(R.raw.car_list);
        return new Gson().fromJson(json, new TypeToken<Boolean>() {
        }.getType());
    }

    public  List<AllVehiclePositionBean> getVehiclePosition() {
        String json = readJsonFromRaw(R.raw.all_vehicle_position);
        return new Gson().fromJson(json, new TypeToken<List<AllVehiclePositionBean>>() {}.getType());
    }


}
